#!/usr/bin/env sh
set -e
name=redis
[ $1 ] && name=$1

# echo "name=$name"
running=`docker ps | grep $name | awk '{print $2}'`
stoped=`docker ps -a | grep $name | awk '{print $2}'`

# echo $running
# echo $stoped
if [ $running ]
then
    echo "redis 正在运行！ \n6379：应用访问端口号 "
    exit
fi

if [ $stoped ]
then
    echo "redis 重新启动！ \n6379：应用访问端口号 "
    docker start $name > /dev/null 2>&1
    exit
fi
docker run -d --name $name -p 6379:6379 redis > /dev/null 2>&1
if [ $? != 0 ]
then
    echo 'redis未能正常启动！'
else
    [ `docker ps | grep $name | awk '{print $2}'` ] && echo "success! \n6379：应用访问端口号"
fi
